<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body style="height: 2000px">
    <script>
      function scrollTop() {
        var scrollTop = document.documentElement.scrollTop;
        console.log("滚动条位置：" + scrollTop);
      }

      function throttle(fn, delay) {
        let flag = true;
        return () => {
          if (flag) {
            flag = false;
            setTimeout(() => {
              fn();
              flag = true;
            }, delay);
          }
        };
      }

      window.onscroll = throttle(scrollTop, 3000);
    </script>
  </body>
</html>
